package com.cls.client.controller;

import com.cls.business.entity.DeclareTopic;
import com.cls.business.entity.TopicPlan;
import com.cls.business.service.IDeclareTopicService;
import com.cls.business.service.ITopicPlanService;
import com.cls.common.entity.ResponseVO;
import com.cls.system.entity.Configure;
import com.cls.system.service.IConfigureService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 客户端数据页面
 *
 * @className: ClientController.java
 * @description:
 * @author: Carey
 * @createDate 2020/11/9 10:46 上午
 **/
@RestController
@RequestMapping("client/")
@RequiredArgsConstructor
public class ClientController {

    private final IConfigureService configureService;

    private final ITopicPlanService topicPlanService;

    private final IDeclareTopicService declareTopicService;


    /**
     * 根据 declareTopicId 查询 总分
     *
     * @return score 得分
     * @author Carey
     * @description
     * @date 2020/11/11 3:43 下午
     */
    @GetMapping("getAppraisalResultScore/{id}")
    public ResponseVO checkApplyProjectInfoTable(@PathVariable Long id) {
        DeclareTopic byId = declareTopicService.getById(id);
        Double score = byId.getScore();
        return ResponseVO.success(score);
    }


    /**
     * 获取申请流程 类型
     *
     * @return a
     * @author Carey
     * @description
     * @date 2020/11/11 3:43 下午
     */
    @GetMapping("getConfigure/{year}")
    public ResponseVO getBusinessType(@PathVariable String year) {
        TopicPlan plan = topicPlanService.selectByPeriod(year);
        if (plan == null) {
            return ResponseVO.failure("期次不存在!");
        }

        Map<String, Object> mpConfigure = new HashMap<>();
        Configure configure = configureService.getById(plan.getConfigureId());
        if (configure != null) {
            mpConfigure.put("businessType", configure.getBusinessTypeCode());
            mpConfigure.put("isTopicLev", configure.getIsTopicLev());
        } else {
            mpConfigure.put("businessType", null);
            mpConfigure.put("isTopicLev", null);
        }
        return ResponseVO.success(mpConfigure);
    }
}
